/**
 * 全排列
 */
function permutation(nums) {
    var result = []
                
    var book = []
    for (var i = 0; i < nums.length(); i++) {
        book.addLast(false)
    }
                
    var p = []
    function dfs(index) {
        if (index == nums.length()) {
            result.addLast(p.copy())
            return
        }
                
        for (var i = 0; i < nums.length(); ++i) {
            if (!book[i]) {
                book[i] = true
                p.addLast(nums[i])
                dfs(index + 1)
                p.removeLast()
                book[i] = false
            }
        }
    }
                
    dfs(0)
                
    return result
}

var result = permutation([1, 2, 3])
for (var i = 0; i < result.length(); ++i) {
    println(result[i])
}
